package cn.smxy.comment.controller;

import cn.smxy.comment.service.CommentService;
import cn.smxy.dto.CommentCountDto;
import cn.smxy.param.CommentUserPage;
import cn.smxy.pojo.Comment;
import cn.smxy.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 添加评论接口
     * @param comment
     * @return
     */
    @PostMapping("/save")
    public R save(@RequestBody Comment comment) {
        return commentService.save(comment);
    }

    /**
     * 获取作品评论接口
     * @param plantId
     * @return
     */
    @GetMapping("/plant/{plantId}")
    public R commentPlant(@PathVariable Long plantId) {
        return commentService.commentPlant(plantId);
    }

    /**
     * 获取用户评论接口
     * @param commentUserPage
     * @return
     */
    @PostMapping("/user")
    public R commentUser(@RequestBody CommentUserPage commentUserPage) {
        return commentService.commentUser(commentUserPage);
    }

    /**
     * 删除对应作品评论的接口
     * @param plantId
     * @return
     */
    @DeleteMapping("/remove/works/{plantId}")
    public R removeByPlantId(@PathVariable Long plantId) {
        return commentService.removeByPlantId(plantId);
    }

    // TODO:管理员模块

    /**
     * 删除对应用户的评论的接口
     * @param userId
     * @return
     */
    @DeleteMapping("/remove/{userId}")
    public R removeById(@PathVariable Long userId) {
        return commentService.removeById(userId);
    }


    /**
     * 获取各作品评论数接口
     * @return
     */
    @GetMapping("/count")
    public List<CommentCountDto> getCount() {
        return commentService.getCount();
    }
}
